/* eslint-disable */
export const calcDate = (date1, date2) => {
	let date3 = date2 - date1
	let days = Math.floor(date3 / (24 * 3600 * 1000))
	let leave1 = date3 % (24 * 3600 * 1000) //计算天数后剩余的毫秒数
	let hours = Math.floor(leave1 / (3600 * 1000))
	let leave2 = leave1 % (3600 * 1000) //计算小时数后剩余的毫秒数
	let minutes = Math.floor(leave2 / (60 * 1000))
	let leave3 = leave2 % (60 * 1000) //计算分钟数后剩余的毫秒数
	let seconds = Math.round(date3 / 1000)
	return {
		leave1,
		leave2,
		leave3,
		days: days,
		hours: hours,
		minutes: minutes,
		seconds: seconds,
	}
}
export function secondToTime (seconds) {
	if (seconds != null && seconds != 0) {
		let day = parseInt(seconds / 86400)
		seconds = seconds % 86400
		let hour = parseInt(seconds / 3600)
		seconds = seconds % 3600
		let minute = parseInt(seconds / 60)
		seconds = seconds % 60
		return day > 0 ? `${day}天${hour}小时${minute}分${seconds}秒` : `${hour}小时${minute}分${seconds}秒`
	} else {
		return ''
	}
}
/**
 * 日期格式化
 */
export function dateFormat (date, format) {
	format = format || 'yyyy-MM-dd hh:mm:ss'
	if (date !== 'Invalid Date') {
		let o = {
			"M+": date.getMonth() + 1, //month
			"d+": date.getDate(), //day
			"h+": date.getHours(), //hour
			"m+": date.getMinutes(), //minute
			"s+": date.getSeconds(), //second
			"q+": Math.floor((date.getMonth() + 3) / 3), //quarter
			"S": date.getMilliseconds() //millisecond
		}
		if (/(y+)/.test(format)) format = format.replace(RegExp.$1,
			(date.getFullYear() + "").substr(4 - RegExp.$1.length))
		for (let k in o)
			if (new RegExp("(" + k + ")").test(format))
				format = format.replace(RegExp.$1,
					RegExp.$1.length === 1 ? o[k] :
						("00" + o[k]).substr(("" + o[k]).length))
		return format
	}
	return ''

}

/**
 * 当前时间戳
 */
export function dateNow () {
	return dateFormat(new Date(), "yyyyMMddhhmmss")
}

//如果time2大于time1 返回true 否则 返回false
export function compareTime (time1, time2) {
	if (time_to_sec(time2) - time_to_sec(time1) > 0) {
		return true
	}
	return false
}

//将时分秒转为时间戳
function time_to_sec (time) {
	if (time !== null) {
		var s = ""
		var hour = time.split(":")[0]
		var min = time.split(":")[1]
		s = Number(hour * 3600) + Number(min * 60)
		return s
	}
}
